/**
 * 订货单操作控制类
 * StockorderAction.java
 * Copyright (C) 2013 Gank
 * Simple Currency Trade System
 * 
 */
package com.gank.ct.action;

import java.util.ArrayList;
import java.util.List;

import com.gank.ct.domain.Client;
import com.gank.ct.domain.Employee;
import com.gank.ct.domain.Merchandise;
import com.gank.ct.domain.Stockorder;
import com.gank.ct.service.IClientService;
import com.gank.ct.service.IEmployeeService;
import com.gank.ct.service.IMerchandiseService;
import com.gank.ct.service.IStockorderService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Copyright (C) 2013:Gank<br/>
 * Project:Curreny Trade<br/>
 * Module ID:<br/>
 * Comments:Simple Currency Trade System<br/>
 * JDK version used:JDK1.6<br/>
 * Package:com.gank.ct.action<br/>
 * Author:Michael Wu<br/>
 * Create Date:2013-11-3<br/>
 * Modified By:<br/>
 * Modified Date:<br/>
 * Why & What is modified:<br/>
 * Version:0.1<br/>
 */
@SuppressWarnings("serial")
public class StockorderAction extends ActionSupport {
	// 订货单业务处理接口
	private IStockorderService stockorderService;
	private Stockorder stockorder = new Stockorder();
	// 查询结果集
	private List<Stockorder> stockorders = new ArrayList<Stockorder>();
	// 操作结束后跳转的地址
	private String finish_Url;
	// 要删除的订货单ID
	private String[] stockorderId;
	// 客户档案业务处理接口
	private IClientService clientService;
	// 员工档案业务处理接口
	private IEmployeeService employeeService;

	// 商品档案业务处理接口
	private IMerchandiseService merchandiseService;
	// 客户档案下拉框数据
	private List<Client> clients = new ArrayList<Client>();
	// 员工档案下拉框数据
	private List<Employee> employees = new ArrayList<Employee>();
	// 商品档案下拉框数据
	private List<Merchandise> merchandises = new ArrayList<Merchandise>();

	/**
	 * 订货单查询
	 * 
	 * @return
	 */

	public String findStockorder() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockorders = stockorderService.findStockorder(stockorder);
		return "findStockorder";

	}

	/**
	 * 订货单保存
	 * 
	 * @return
	 */
	public String saveStockorder() {
		stockorderService.saveStockorder(stockorder);
		finish_Url = "stockorderAction!findStockorder.action";
		return "finish";
	}

	/**
	 * 订货单删除
	 * 
	 * @return
	 */
	public String deleteStockorder() {
		stockorderService.deleteStockorder(stockorderId);
		finish_Url = "stockorderAction!findStockorder.action";
		return "finish";
	}

	/**
	 * 订货单更新
	 * 
	 * @return
	 */
	public String updateStockorder() {
		stockorderService.updateStockorder(stockorder);
		finish_Url = "stockorderAction!findStockorder.action";
		return "finish";
	}

	/**
	 * 订货单更新前查询
	 * 
	 * @return
	 */
	public String preUpdateStockorder() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockorder = stockorderService.findStockorder(stockorder).get(0);
		return "updateStockorder";
	}

	/**
	 * 订货单查询前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preFindStockorder() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preFindStockorder";

	}

	/**
	 * 订货单新增前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preSaveStockorder() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preSaveStockorder";

	}

	/**
	 * 进货单查询
	 * 
	 * @param code
	 *            订货单编码
	 * @return
	 */

	public int findStockorderByCode(String code) {
		stockorder = new Stockorder();
		stockorder.setCode(code);
		stockorders = stockorderService.findStockorder(stockorder);
		return stockorders.size();

	}

	/**
	 * @return the stockorderService
	 */
	public IStockorderService getStockorderService() {
		return stockorderService;
	}

	/**
	 * @param stockorderService
	 *            the stockorderService to set
	 */
	public void setStockorderService(IStockorderService stockorderService) {
		this.stockorderService = stockorderService;
	}

	/**
	 * @return the stockorder
	 */
	public Stockorder getStockorder() {
		return stockorder;
	}

	/**
	 * @param stockorder
	 *            the stockorder to set
	 */
	public void setStockorder(Stockorder stockorder) {
		this.stockorder = stockorder;
	}

	/**
	 * @return the stockorders
	 */
	public List<Stockorder> getStockorders() {
		return stockorders;
	}

	/**
	 * @param stockorders
	 *            the stockorders to set
	 */
	public void setStockorders(List<Stockorder> stockorders) {
		this.stockorders = stockorders;
	}

	/**
	 * @return the finish_Url
	 */
	public String getFinish_Url() {
		return finish_Url;
	}

	/**
	 * @param finish_Url
	 *            the finish_Url to set
	 */
	public void setFinish_Url(String finish_Url) {
		this.finish_Url = finish_Url;
	}

	/**
	 * @return the stockorderId
	 */
	public String[] getStockorderId() {
		return stockorderId;
	}

	/**
	 * @param stockorderId
	 *            the stockorderId to set
	 */
	public void setStockorderId(String[] stockorderId) {
		this.stockorderId = stockorderId;
	}

	/**
	 * @return the clientService
	 */
	public IClientService getClientService() {
		return clientService;
	}

	/**
	 * @param clientService
	 *            the clientService to set
	 */
	public void setClientService(IClientService clientService) {
		this.clientService = clientService;
	}

	/**
	 * @return the employeeService
	 */
	public IEmployeeService getEmployeeService() {
		return employeeService;
	}

	/**
	 * @param employeeService
	 *            the employeeService to set
	 */
	public void setEmployeeService(IEmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	/**
	 * @return the merchandiseService
	 */
	public IMerchandiseService getMerchandiseService() {
		return merchandiseService;
	}

	/**
	 * @param merchandiseService
	 *            the merchandiseService to set
	 */
	public void setMerchandiseService(IMerchandiseService merchandiseService) {
		this.merchandiseService = merchandiseService;
	}

	/**
	 * @return the clients
	 */
	public List<Client> getClients() {
		return clients;
	}

	/**
	 * @param clients
	 *            the clients to set
	 */
	public void setClients(List<Client> clients) {
		this.clients = clients;
	}

	/**
	 * @return the employees
	 */
	public List<Employee> getEmployees() {
		return employees;
	}

	/**
	 * @param employees
	 *            the employees to set
	 */
	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}

	/**
	 * @return the merchandises
	 */
	public List<Merchandise> getMerchandises() {
		return merchandises;
	}

	/**
	 * @param merchandises
	 *            the merchandises to set
	 */
	public void setMerchandises(List<Merchandise> merchandises) {
		this.merchandises = merchandises;
	}

}
